[script]
n0=;
n1=;          this section deals with all joining and leaving from channels,
n2=;          i.e. on join, on part, on quit, on kick and associated tasks,
n3=;          such as clone/join flood/mass kick detection
n4=;
n5=alias account {
n6=  if ix.netcom.com isin $1 return 4
n7=  elseif netcom isin $1 return 1
n8=  elseif ($isnumericip($1)) return 2
n9=  elseif ((1 !isin $1) && (2 !isin $1) && (3 !isin $1) && (4 !isin $1) && (5 !isin $1) && (6 !isin $1) && (7 !isin $1) && (8 !isin $1) && (9 !isin $1) && (0 !isin $1)) return 3
n10=  return 4
n11=}
n12=alias nonum return $right($1,$calc($len($1) - 1))
n13=alias jtxt if (%urd) { z | echo 1 $me $2 $+ : 3,0 $+ $3 $+ : $1 ( $+ $4 $+ ) }
n14=alias banned {
n15=  ; /* shithead matches a ban... gotta kick and ban him */
n16=  set %chans $readini $ul whereban $ma($1)
n17=  if ((%chans = $null) || ($2 isin %chans)) {
n18=    set %reason $readini $ul whyban $ma($1)
n19=    mode $2 +b-o $ma($1) $1
n20=    if %reason != $null kick $2 $1 banned: %reason
n21=    else kick $2 $1 %default
n22=    writeini $ul lastused $ma($1) $ctime
n23=    rtb $ma(%nick) $2
n24=    if (%ekick) {
n25=      if (%ckick) set %temp $2
n26=      else set %temp -a
n27=      altech %temp %dis3 $+ Shitlisted User! %dis4 Kicking $1 from $2
n28=      alert
n29=    }
n30=  }
n31=  else { altech $2 %dis3 $+ Warning! %dis4 matches ban on $ma($1) $+ , but its not banned on $2 }
n32=}
n33=alias newpeak {
n34=  set %highcount [ $+ [ $1 ] ] $nick($1,0)
n35=  set %whenpeak [ $+ [ $1 ] ] $realtime $+ , $day $adate
n36=  if (%peaknotice [ $+ [ $1 ] ] ) {
n37=    raw -q notice $1 :New peak at $nick($1,0) for $1 ( $+ $realtime $+ , $day $adate $+ )
n38=    raw -q notice $me :New peak at $nick($1,0) for $1 ( $+ $realtime $+ , $day $adate $+ )
n39=  }
n40=  altech -a %dis10 $+ New peak at $nick($1,0) for $1 ( $+ $realtime $+ , $day $adate $+ )
n41=}
n42=alias checkpeak {
n43=  if %highcount [ $+ [ $1 ] ] = $null newpeak $1
n44=  else if ($nick($1,0) > %highcount [ $+ [ $1 ] ] ) newpeak $1
n45=}
n46=alias getkey set %key [ $+ [ $1 ] ] $channel($1).key
n47=alias joinperform {
n48=  if (%haveoptions [ $+ [ $1 ] ] ) set %chan $1
n49=  else set %chan Unspecified_Channels
n50=  %i = 0
n51=  :nx
n52=  inc %i
n53=  set %temp $readini $mircdiroptions\options.ini OnJoin  [ [ %chan ] $+ [ %i ] ]
n54=  if (%temp != $null) { .timer 1 %i %temp | goto nx }
n55=}
n56=alias ijoined {
n57=  if $1 = %rchan halt
n58=  set %updatedial [ $+ [ $1 ] ] $false
n59=  unset %tviknowimbanned [ $+ [ $1 ] ]
n60=  .timer 1 1 getkey $1
n61=  set %tvfb [ $+ [ $1 ] ] $false
n62=  set %tvimanop [ $+ [ $1 ] ] $false | .auser 70 $me | who $1
n63=  set %myadr $a5($me) | unset %tvnchg* | unset %joins*
n64=  unset %nk* | unset %conn* | unset %tvtxtfl*
n65=  .timer 1 2 if ($me isop $1) emode $1
n66=  joinperform $1
n67=  if (%idlekick [ $+ [ $1 ] ] ) remini $mircdiridle.ini $1
n68=  if %ticks [ $+ [ $1 ] ] != $null altech $1 %dis10 $+ Join synced for $1 in $calc(($ticks - (%ticks [ $+ [ $1 ] ] )) / 1000) seconds
n69=  unset %ticks [ $+ [ $1 ] ]
n70=  altech $1 %dis10 $+ Updating internal address list for $1 | .timer 1 3 ckmd $1
n71=  remini $mircdirrepeat.ini $1
n72=}
n73=on 1:KICK:#:{
n74=  log Kicked: $knick was kicked from $chan by $fulladdress ( $+ $strip($1-) $+ )
n75=  if (%urd) { z | echo 1 $me $chan $+ : 3,0 $+ $knick was kicked by $nick ( $+ $1- $+ ) }
n76=  if ($knick = $me) { 
n77=    set %tvimanop [ $+ [ $chan ] ] $false | set %icmpnick $nick | .timer 1 60 unset %icmpnick
n78=    altech -s %dis10 $+ You have been kicked off $chan by $nick
n79=    set %ticks [ $+ [ $chan ] ] $ticks
n80=    if $nick != ChanServ {
n81=      echo 3 -s Looking up address...
n82=      .enable #autoicmp | userhost $nick
n83=    }
n84=    if (%altrejoin) {
n85=      ; alternate auto-rejoin routine, which can re-join a keyed channel
n86=      unset %ticks [ $+ [ $chan ] ]
n87=      if (%key [ $+ [ $chan ] ]  != $null) { altech -s %dis10 $+ Attempting to rejoin $chan $+ ... | .timer 1 2 join $chan %key [ $+ [ $chan ] ] }
n88=      else { altech -s %dis10 $+ Attempting to rejoin $chan $+ ... | .timer 1 1 join $chan }
n89=    }
n90=    dh
n91=  }
n92=  if (%haveoptions [ $+ [ $chan ] ] ) set %kickchan $chan
n93=  else set %kickchan other
n94=  if (($me isop $chan) && (%massdeop [ $+ [ %kickchan ] ] )) {
n95=    if (($isop($nick,$chan)) && (%opexkick [ $+ [ %kickchan ] ] )) goto skip
n96=    if ($notmaster($nick,$chan)) {
n97=      if (%kicks [ $+ [ $a3($nick) ] ] >= 2) { 
n98=        adeop $a3($nick) $chan
n99=        kickall $a3($nick) $chan %masskickmsg
n100=        if (%ekick) {
n101=          if (%ckick) set %temp $chan
n102=          else set %temp -a
n103=          altech %temp %dis3 $+ Mass Kick! %dis4 Kicking $nick from $chan
n104=        }
n105=        if (%smk = ding) ding
n106=        elseif (%smk = speak) speak mass kick, kicking $nick from $nonum($chan)
n107=        elseif (%smk != none) splay %smk
n108=      }
n109=      else { inc %kicks [ $+ [ $a3($nick) ] ] | .timer 1 10 unset %kicks [ $+ [ $a3($nick) ] ] }
n110=    }
n111=  }
n112=  :skip
n113=  if ($isfriend($knick,$chan)) lastseen $knick
n114=  elseif (%idlekick [ $+ [ $chan ] ] ) remini $mircdiridle.ini $chan $nick    
n115=}
n116=on +10:JOIN:#: if (($me isop $chan) && (%banlist)) banned $nick $chan
n117=on 1:JOIN:#:{
n118=  jtxt $nick $chan Joined $address
n119=  if ($nick = $me) { ijoined $chan | halt }
n120=  elseif ($isfriend($nick,$chan)) {
n121=    if $ulevel = 70 {
n122=      if (%uech) altech $chan %dis5 $+ $nick (your clone) has joined $chan
n123=      else altech %dis5 $+ $nick (your clone) has joined $chan
n124=      if (%sjoin = ding) ding
n125=      elseif (%sjoin = speak) speak $nick $+ , your clone, has joined $nonum($chan)
n126=      elseif (%sjoin != none) splay %sjoin
n127=    }
n128=    else {
n129=      if (%uech) altech $chan %dis5 $+ $nick ( $+ $wordlevel($ulevel) $+ ) has joined $chan
n130=      else altech %dis5 $+ $nick ( $+ $wordlevel($ulevel) $+ ) has joined $chan
n131=      if (%sjoin = ding) ding
n132=      elseif (%sjoin = speak) speak $nick, $wordlevel($ulevel) $+ , has joined channel $nonum($chan)
n133=      elseif (%sjoin != none) splay %sjoin
n134=    }
n135=    set %rn $rnick.nick($nick) | lastseen $nick
n136=    if ((%rn != $nick) && (%rn != $null)) { 
n137=      if (%uech) altech $chan %dis5 $+ $nick is really %rn $+ !
n138=      else altech %dis5 $+ $nick is really %rn $+ !
n139=    }
n140=    if ((%autogreet) && ($ulevel != 70)) {
n141=      if (%tvjustgreeted [ $+ [ $a3($nick) ] ] != $true) {
n142=        set %tvjustgreeted [ $+ [ $a3($nick) ] ] $true
n143=        .timer 1 60 unset %tvjustgreeted [ $+ [ $a3($nick) ] ]
n144=        if (%infolines) {
n145=          set %info $readini $ul info %rn
n146=          if %info != $null msg $chan %greetstart $+ $nick $+ %greetend 1,0( $+ %info $+ )
n147=          else msg $chan %greetstart $+ $nick $+ %greetend
n148=        }
n149=        else msg $chan %greetstart $+ $nick $+ %greetend
n150=      }
n151=    }
n152=  }
n153=  if (%haveoptions [ $+ [ $chan ] ] ) set %joinchan $chan
n154=  else set %joinchan other  
n155=  if ($me isop $chan) && ($isfriend($nick,$chan)) {
n156=    if ((($ulevel = 60) || ($ulevel = 70))) {
n157=      if ((%opbots [ $+ [ %joinchan ] ] ) || (%opmasters [ $+ [ %joinchan ] ] ) || (%opops [ $+ [ %joinchan ] ] )) mode $chan +o $nick
n158=      elseif (%voiceall [ $+ [ %joinchan ] ] ) mode $chan +v $nick
n159=    }
n160=    elseif $ulevel = 50 {
n161=      if ((%opmasters [ $+ [ %joinchan ] ] ) || (%opops [ $+ [ %joinchan ] ] )) mode $chan +o $nick
n162=      elseif (%voiceall [ $+ [ %joinchan ] ] ) mode $chan +v $nick
n163=    }
n164=    elseif $ulevel = 40 {
n165=      if (%opops [ $+ [ %joinchan ] ] ) mode $chan +o $nick
n166=      elseif (%voiceall [ $+ [ %joinchan ] ] ) mode $chan +v $nick
n167=    }
n168=    elseif ((%autovoice [ $+ [ %joinchan ] ] ) || (%voiceall [ $+ [ %joinchan ] ] )) mode $chan +v $nick
n169=  }
n170=  elseif ($me isop $chan) {
n171=    if ((%voiceall [ $+ [ %joinchan ] ] ) && ($ulevel != 15)) mode $chan +v $nick
n172=  }
n173=  if (%peak [ $+ [ %joinchan ] ] ) checkpeak $chan
n174=  log Joined: $fulladdress joined $chan
n175=  if (%havecustom [ $+ [ %joinchan ] ] ) {
n176=    if ((%anyone [ $+ [ %joinchan ] ] ) || ($notfriend($nick,$chan))) {
n177=      set %nick $nick
n178=      if (%haveoptions [ $+ [ $chan ] ] ) $ro(CustomJoin, [ [ $chan ] $+ actual ] )
n179=      else $ro(CustomJoin,Unspecified_Channelsactual)
n180=    }
n181=  }
n182=  if (($isfriend($nick,$chan)) || ($ulevel = 70)) halt
n183=  if (%autokick [ $+ [ $chan ] ] = on) { 
n184=    mode $chan -o+b $nick $address($nick,4)
n185=    kick $chan $nick %autokickmsg | rtb $address($nick,4) $chan | halt
n186=  }
n187=  if (%idlekick [ $+ [ %joinchan ] ] ) writeini $mircdiridle.ini $chan $nick $ctime
n188=  if (%joinflood [ $+ [ %joinchan ] ] ) {
n189=    inc %joins [ $+ [ $chan [ $+ [ $site ] ] ] ]
n190=    .timer 1 %joinin unset %joins [ $+ [ $chan [ $+ [ $site ] ] ] ]
n191=    if (($me isop $chan) && (%joins [ $+ [ $chan [ $+ [ $site ] ] ] ] >= %joinis)) { 
n192=      kickban $a2($nick) $chan %joinfloodmsg
n193=      rtb $a2($nick) $chan
n194=      if (%ekick) {
n195=        if (%ckick) set %temp $chan
n196=        else set %temp -a
n197=        altech %temp %dis3 $+ Join Flood! %dis4 Kick-Banned $nick ( $+ $a3($nick) $+ ) from $chan
n198=      }
n199=      if (%sjoinf = ding) ding
n200=      elseif (%sjoinf = speak) join flood detected, kicking $nick
n201=      elseif (%sjoinf != none) splay %sjoinf
n202=    }
n203=  }
n204=  if ($me isop $chan) && (%clone [ $+ [ %joinchan ] ] ) {
n205=    %n = 0
n206=    :findclone
n207=    inc %n
n208=    set %nick $ialchan($a2($nick),$chan,%n).nick
n209=    if %nick != $null {
n210=      if ((%nick != $nick) && ($notfriend(%nick,$chan)) && ($a2(%nick) != $a2($me))) goto clone
n211=      goto findclone
n212=    }
n213=  }  
n214=  if (%whois [ $+ [ %joinchan ] ] ) {
n215=    if ((($me isop $chan) && (%whoisopped [ $+ [ %joinchan ] ] )) || (%whoisalways [ $+ [ %joinchan ] ] )) {
n216=      if (($nick != W) && ($nick != X) && ($nick != ChanServ) && ($nick != Q)) autowhois $nick
n217=    }
n218=  }
n219=  if (($me isop $chan) && (%excclients [ $+ [ %joinchan ] ] )) {
n220=    if (($nick != W) && ($nick != X) && ($nick != ChanServ) && ($nick != Q)) {
n221=      set %nk [ $+ [ $site ] ] $nick | set %conn [ $+ [ $site ] ] 0 | account $site
n222=      if $result = 4 who $site
n223=      elseif (%eflood) {
n224=        if $result = 1 echo -s 14 $+ $nick appears to be on a netcom shell, skipping ip check
n225=        elseif $result = 2 echo -s 14 $+ $nick has a numeric ip, skipping ip check
n226=        elseif $result = 3 echo -s 14 $+ $nick appears to be on a unix account, skipping ip check
n227=      }
n228=      .timer 1 15 unset %conn [ $+ [ $site ] ] | .timer 1 15 unset %nk [ $+ [ $site ] ]
n229=    }
n230=  }
n231=  set %lv $readini $ul level $nick
n232=  if ((%lv > 18) && (%lv < 65) && (%lv != $null) && ($gl($nick) = 1)) altech -a %dis3 $+ Imposter Alert! %dis4 $nick joined $chan $+ , but $a3($nick) is not known to belong to the real $nick
n233=  halt
n234=  :clone
n235=  if (%ckick) set %temp $chan
n236=  else set %temp -a
n237=  if (%tvkclone [ $+ [ $site ] ] = yes) {
n238=    ; hey, this guy had a clone kicked less than 60 seconds ago... lets ban him
n239=    if %maxmodes != 4 { mode $chan -oo $nick %nick | mode $chan +bb $nick %nick $a2($nick) $a3($nick) }
n240=    else mode $chan -oo+bb $nick %nick $a2($nick) $a3($nick)
n241=    .timer 1 %bantime mode $chan -bb $a2($nick) $a3($nick)
n242=    kickall $a2($nick) $chan %clonemsg
n243=    kickall $a3($nick) $chan %clonemsg
n244=    if (%ekick) altech %temp %dis3 $+ Mass Clones Detected! %dis4 Banning $a3($nick) and $a2($nick) on $chan
n245=  }
n246=  else {
n247=    if (%kickclone [ $+ [ %joinchan ] ] ) {
n248=      set %tvkclone [ $+ [ $site ] ] yes | .timer 1 60 unset %tvkclone [ $+ [ $site ] ]
n249=      mode $chan +b %nick $+ !*@* | kick $chan %nick %ghostmsg | .timer 1 60 mode $chan -b %nick $+ !*@*
n250=      if (%ekick) altech %temp %dis3 $+ Clone Detected! ( $+ %nick and $nick $+ ) %dis4 Kicking %nick from $chan
n251=    }
n252=    elseif (%noticeclone [ $+ [ %joinchan ] ] ) {
n253=      raw -q notice $chan :4Clone Detected! 3( $+ %nick and $nick $+ )
n254=      raw -q notice $me :4Clone Detected! 3( $+ %nick and $nick $+ )   
n255=    }
n256=    elseif (%ekick) altech %temp %dis3 $+ Clone Detected on $chan $+ ! %dis4 ( $+ %nick and $nick $+ )
n257=  }
n258=  if (%sclone = ding) ding
n259=  elseif (%sclone = speak) speak clones detected on $nonum($chan)
n260=  elseif (%sclone != none) splay %sclone
n261=}
n262=on 1:PART:#:{
n263=  jtxt $nick $chan Left $address
n264=  if $nick = $me {
n265=    set %tvimanop [ $+ [ $chan ] ] $false
n266=    if (%urd) { z | echo 3 $me You have left $chan }
n267=  }
n268=  elseif ($isfriend($nick,$chan)) lastseen $nick
n269=  else {
n270=    if (%idlekick [ $+ [ $chan ] ] ) remini $mircdiridle.ini $chan $nick
n271=    set %lastpart [ $+ [ $chan ] ] $a3($nick)
n272=  }
n273=  log Part: $fulladdress left $chan
n274=}
n275=on 1:QUIT:{
n276=  if (%urd) { z | echo 1 $me Signoff: $nick has left IRC ( $+ $1- $+ ) }
n277=  log Quit: $nick quit IRC ( $+ $strip($1-) $+ )
n278=  set %q 0
n279=  :nx
n280=  inc %q
n281=  if $chan(%q) != $null {
n282=    remini $mircdiridle.ini $chan(%q) $nick
n283=    goto nx
n284=  }
n285=}
n286=on 19:QUIT:{
n287=  lastseen $nick
n288=  if (%urd) { z | echo 1 $me Signoff: $nick has left IRC ( $+ $1- $+ ) }
n289=  log Quit: $nick quit IRC ( $+ $strip($1-) $+ )
n290=}
